ExtensionUtils.installImporter(extension);
// give extension prefs access to their own extension object
- ExtensionUtils.getCurrentExtension = () => extension;
+ ExtensionUtils.setCurrentExtension(extension);
const prefsModule = extension.imports.prefs;
prefsModule.init(extension.metadata);
/* exported ExtensionState, ExtensionType, getCurrentExtension,
getSettings, initTranslations, gettext, ngettext, pgettext,
openPrefs, isOutOfDate, installImporter, serializeExtension,
- deserializeExtension */
+ deserializeExtension, setCurrentExtension */
// Common utils for the extension system and the extension
// preferences tool
const Config = imports.misc.config;
+let Main = null;
+
+try {
+ Main = imports.ui.main;
+} catch (error) {
+ // Only log the error if it is not due to the
+ // missing import.
+ if (error?.name !== 'ImportError')
+ console.error(error);
+}
+
+let _extension = null;
+
var ExtensionType = {
SYSTEM: 1,
PER_USER: 2,
'canChange',
];
+/**
+ * @param {object} extension the extension object to use in utilities like `initTranslations()`
+ */
+function setCurrentExtension(extension) {
+ if (Main)
+ throw new Error('setCurrentExtension() can only be called from outside the shell');
+
+ _extension = extension;
+}
+
/**
* getCurrentExtension:
*
* an extension.
*/
function getCurrentExtension() {
+ if (_extension)
+ return _extension;
+
let stack = new Error().stack.split('\n');
let extensionStackLine;